package com.ewhale.feitengguest.presenter.user.task;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.BannerDto;
import com.ewhale.feitengguest.dto.ClassificationDto;
import com.ewhale.feitengguest.dto.NavigationDto;
import com.ewhale.feitengguest.dto.RankDto;
import com.ewhale.feitengguest.dto.TaskListDto;
import com.ewhale.feitengguest.view.user.task.TaskView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

import java.util.List;

public class TaskPresenter extends IPresenter {
    public void getBannerList() {
        request(1, ApiHelper.TASK_API.getBannerList(), null);
    }

    public void getClassification() {
        request(2, ApiHelper.TASK_API.getAllClassificationList(), null);
    }

    public void loadBannerDetail(long bannerId, int position) {
        mView.showProLoading();
        request(3, ApiHelper.TASK_API.getBannerDetail(bannerId), position);
    }

    public void getTaskList(int pageNum, int cateId) {
        request(4, ApiHelper.TASK_API.getTaskList(pageNum, 10, cateId,3), pageNum);
    }

    public void getNavigationList() {
        request(5, ApiHelper.TASK_API.getNavigationList(), null);
    }

    public void getRanking() {
        request(6, ApiHelper.TASK_API.getRanking(), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((TaskView) mView).showBannerList((List<BannerDto>) result);
                break;
            case 2:
                ((TaskView) mView).showClassification((List<ClassificationDto>) result);
                break;
            case 3:
                ((TaskView) mView).showBannerDetails((String) result, (int) data);
                break;
            case 4:
                ((TaskView) mView).showTaskList((List<TaskListDto>) result, (int) data);
                break;
            case 5:
                ((TaskView) mView).showNavigationList((List<NavigationDto>) result);
                break;
            case 6:
                ((TaskView) mView).showRanking((RankDto) result);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
